home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11577 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Newbie needs help w/ARGV ARGC
  5. Date: 24 Mar 1996 22:00 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <24MAR199622002745@erich.triumf.ca>
  9. References: <4j4ja1$dc3@mtinsc01-mgt.ops.worldnet.att.net>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4j4ja1$dc3@mtinsc01-mgt.ops.worldnet.att.net>, dslayer@worldnet.att.net (Raymond Joh) writes...
  14. >I have spent three days attempting to determine why my command line
  15. >arguments  are failing...
  16. >I am using MS Quick C 2.5
  17. >I just want to be able to enter two file paths at the command line.
  18. >Here is my code: 
  19. >#include <stdio.h>
  20. >#include <stdlib.h>
  21.  
  22. >main(int argc, char *argv[],char *envp[])
  23. >{
  24. >FILE *ofp,*nfp;
  25. >char ch;
  26. >gets(*argv);
  27.  
  28. Why??  This will require the user to enter something, and (I think) over-write
  29. the command-line arguments.  In any case, _never_ use gets() - always use
  30. fgets() instead.
  31.  
  32. >if (argc!=3)
  33. >  {
  34. >  printf("Enter: <source> <destination>\n");
  35. >  exit(1);
  36. >  }
  37. >Code countinues but when I enter my command line input such as:
  38. >A:\readme.txt  A:\newfile.txt
  39. >I get my arvc error message above
  40. >I'm sure I've missed something simple but it has me stumped.
  41. >(win95 if OS matters.)
  42.  
  43.  
  44. I think you are confused about what "command line arguments" are.  Command line
  45. arguments are things given following the program name, for example, to start
  46. your program with command line arguments you would say:
  47.     "myprog A:\readme.txt A:\newfile.txt"
  48. all on one line.
  49.  
  50. Then argc ==3 and argv[0] is "myprog", argv[1] is "a:\reame.txt", and argv[2]
  51. is "newfile.txt"
  52.  
  53. Now, can you do this in Win95??  Or will your program have to put up a window
  54. and ask for file names??
  55.  
  56. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  57. Internet: bennett@triumf.ca         | of one another only when one can be
  58. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  59. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  60. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  61. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  62.  
  63.